﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;

namespace QMERP.Infrastructure.EFCore.Mappings
{
    public class TransferLensOrderDetailMapping : IEntityTypeConfiguration<TransferLensOrderDetail>
    {
        public void Configure(EntityTypeBuilder<TransferLensOrderDetail> builder)
        {
            builder.Property(x => x.TransferLensOrderId);
            builder.Property(x => x.OutWarehouseId);
            builder.Property(x => x.InWarehouseId);
            builder.Property(x => x.OutLensId);
            builder.Property(x => x.InLensId);

            builder.HasOne(x => x.OutWarehouse)
               .WithMany(t => t.OutTransferLensOrderDetails)
               .HasForeignKey(m => m.OutWarehouseId)
               .OnDelete(DeleteBehavior.NoAction);
            builder.HasOne(x => x.InWarehouse)
              .WithMany(t => t.InTransferLensOrderDetails)
              .HasForeignKey(m => m.InWarehouseId)
              .OnDelete(DeleteBehavior.NoAction);
            builder.HasOne(x => x.OutLens)
               .WithMany(t => t.OutTransferLensOrderDetails)
               .HasForeignKey(m => m.OutLensId)
               .OnDelete(DeleteBehavior.NoAction);
            builder.HasOne(x => x.InLens)
               .WithMany(t => t.InTransferLensOrderDetails)
               .HasForeignKey(m => m.InLensId)
               .OnDelete(DeleteBehavior.NoAction);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.TransferLensOrderId);
            builder.HasIndex(x => x.OutWarehouseId);
            builder.HasIndex(x => x.InWarehouseId);
            builder.HasIndex(x => x.OutLensId);
            builder.HasIndex(x => x.InLensId);
        }
    }
}
